import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/user/login',
    method: 'post',
    data
  })
}

export function getInfo(token) {
  return request({
    url: '/user/info',
    method: 'get',
    params: { token }
  })
}

export function getDetail(id) {
  return request({
    url: '/user/detail',
    method: 'get',
    params: { id }
  })
}

export function logout() {
  return request({
    url: '/user/logout',
    method: 'post'
  })
}

export function fetchList(query) {
  return request({
    url: '/user/list',
    method: 'get',
    params: query
  })
}

export function setLoop(id, state) {
  return request.post(`/user/${id}/loop/${state}`)
}

export function fetchStore(userId) {
  return request.get(`/user/${userId}/store`)
}

export function fetchStoreDetail(userId) {
  return request.get(`/user/${userId}/storeDetail`)
}

export function addRoles(userId, roleIds) {
  return request.post('/user/roles', { userId, roleIds })
}

export function fetchRoles(userId) {
  return request.get(`/user/${userId}/roles`)
}

export function removeRole(userId, roleId) {
  return request.delete(`/user/${userId}/role/${roleId}`)
}

export function addUser(data) {
  return request.post('/user', data)
}

export function editUser(data) {
  return request.post('/user/update', data)
}

export function deleteUser(id) {
  return request.delete(`/user/${id}`)
}

export function getAllUser() {
  return request.get('/user/all')
}

/**
 * 设置利率
 * @param {id, interestRate} data
 */
export function setInterestRate(data) {
  return request.post('/user/InterestRate', data)
}

export function startAllStore(id) {
  return request.post(`/user/${id}/store/start`)
}
export function stopAllStore(id) {
  return request.post(`/user/${id}/store/stop`)
}

export function getCountInfo(id, startDate, endDate, today) {
  return request({
    url: `/user/${id}/countInfo`,
    method: 'get',
    params: { startDate, endDate, today }
  })
}

export function setPause(id, pause) {
  return request.post(`/user/${id}/pause`, { pause })
}

export function setUserScore(id, value) {
  return request.post(`/user/${id}/score`, { 'score': value })
}

export function getManageInfo(id) {
  return request.get(`/user/${id}/manageInfo`)
}

export function editManageInfo(id, score, interest_rate, order_limit) {
  return request({
    url: `/user/${id}/manageInfo`,
    method: 'post',
    data: { score, interest_rate, order_limit }
  })
}
